<template>
  <div>
    <!-- 查询条件-->
    <el-form :inline="true" :model="SearchDate" class="demo-form-inline">
      <el-form-item label="置业顾问">
        <el-select v-model="SearchDate.eid" placeholder="置业顾问">
          <el-option label="全部" value=""></el-option>
          <el-option
            :label="emp.ename"
            :value="emp.eid"
            v-for="emp in AllEmp"
          ></el-option>
        </el-select>
      </el-form-item>

      <!-- Form -->

<el-dialog title="新增预约信息" :visible.sync="dialogFormVisible">
  <el-form :model="form">
    <el-form-item label="客户名" :label-width="formLabelWidth">
      <el-input v-model="form.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="活动区域" :label-width="formLabelWidth">
      <el-select v-model="form.region" placeholder="请选择活动区域">
        <el-option label="区域一" value="shanghai"></el-option>
        <el-option label="区域二" value="beijing"></el-option>
      </el-select>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
  </div>
</el-dialog>
    

      <span class="demonstration">选择日期</span>
      <el-date-picker
        v-model="value2"
        type="datetimerange"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        align="right"
      >
      </el-date-picker>

      <el-form-item>
        <el-button type="primary" @click="toSearch">查询</el-button>
        <el-button type="success" plain @click="dialogFormVisible = true"
          >新增</el-button
        >
      </el-form-item>
    </el-form>

    <!-- 列表展示 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="#" width="80">
        <!-- <template slot-scope="scope"> -->
        <span style="margin-left: 10px"><el-checkbox></el-checkbox></span>
        <!-- </template> -->
      </el-table-column>

      <el-table-column label="客户名" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.uname }}</span>
        </template>
      </el-table-column>

      <el-table-column label="置业顾问" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.ename }}</span>
        </template>
      </el-table-column>

      <el-table-column label="房间" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.hunm }}</span>
        </template>
      </el-table-column>

      <el-table-column label="开始时间" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.begintime }}</span>
        </template>
      </el-table-column>

      <el-table-column label="结束时间" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.endtime }}</span>
        </template>
      </el-table-column>

      <el-table-column label="状态" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.appstate }}</span>
        </template>
      </el-table-column>

      <el-table-column label="备注" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.log }}</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->

    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[3, 6, 9, 11]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalPage"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 查询条件数据
      SearchDate: {
        eid: "",
        begin: "",
        end: "",
      },
      //弹出表单
      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      formLabelWidth: "120px",
      //所有员工
      AllEmp: [],
      // 列表展示数据
      tableData: [],
      // 分页数据
      totalPage: 0,
      pageSize: "",
      currentPage: "",
      //日期选择
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: "",
      value2: "",
      //建议查询
      userName: [],
      theUser: "",
    };
  },
  created() {
    this.currentPage = 1;
    this.pageSize = 3;
    this.showList();
    this.showEmp();
    this.showUserName();
  },
  mounted() {
    this.userName = this.loadAll();
  },
  methods: {
    //加载用户的信息到推荐搜索
    showUserName() {
      this.$axios
        .get("/ever-user/searchAll")
        .then((res) => {
          var itemsArray = Object.entries(res.data);
          this.userName = itemsArray;
        })
        .catch((err) => {});
    },
    //加载员工列表
    showEmp() {
      this.$axios
        .get("/ever-emp/findAllNoPage/", "")
        .then((res) => {
          this.AllEmp = res.data;
        })
        .catch((err) => {
          console.error(err);
        });
    },
    //查询条件方法和所有数据
    showList() {
      this.$axios
        .post(
          "/ever-appointment/ManagerSelectAll/" +
            this.currentPage +
            "/" +
            this.pageSize +
            "?foo=" +
            new Date().getTime(),
          {
            eid: this.SearchDate.eid,
            begin: this.value2[0],
            end: this.value2[1],
          }
        )
        .then((res) => {
          this.loading = false;
          this.tableData = res.data.orderList;
          this.totalPage = parseInt(res.data.totalPage);
        })
        .catch((err) => {});
    },

    //查询条件方法
    toSearch() {
      this.showList();
    },
    //新增方法
    open() {
      this.$prompt("姓名", "新增", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        //注 ; 上方为邮箱的正则
        inputErrorMessage: "姓名格式不正确",
      })
        .then(({ value }) => {
          this.$message({
            type: "success",
            message: "你的邮箱是: " + value,
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入",
          });
        });
    },
    // 列表展示方法
    handleEdit(index, row) {},
    handleDelete(index, row) {},
    // 分页方法
    handleSizeChange(val) {
      this.pageSize = val;
      this.showList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.showList();
    },

  },
};
</script>
